package com.bxait.utils;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import javax.xml.validation.Validator;

/**
 * @author Chen
 * @description:
 * @ClassName 使用单例模式返回 RestHighLevelClient
 * @create 2023-04-08 16:50
 * @Version 1.0
 */
public class ESClientSingle {
    private static volatile RestHighLevelClient client= null;
    private static String host = "localhost";
    private static int post = 9200;
    private static String scheme = "http";

    // 构造器私有化
    private ESClientSingle() {
    }

    // 使用DCL双端加锁,懒汉式返回
    public static  RestHighLevelClient getInstant(){
        if(client == null){
            synchronized (ESClientSingle.class){
                if(client == null) {
                    client = new RestHighLevelClient(
                            RestClient.builder(new HttpHost(host,post,scheme))
                    );
                }
            }
        }
        return client;
    }
}
